﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using KsWare.Breconium.Core;

namespace Ksx.KoCTool.Tabs.EvalTest {
	/// <summary>
	/// Interaction logic for EvalTest.xaml
	/// </summary>
	public partial class EvalTest : UserControl {
		public EvalTest() {
			InitializeComponent();
		}

		private void ExcecuteButtonClick(object sender, RoutedEventArgs e) {
			var ret=Execute(mJavaScriptTextBox.Text);
			mResultextBox.Text = ret;
		}

		private string Execute(string parameters) { 
			
			var cmd = new Command("eval", parameters);

			try {((App)Application.Current).Server.DefaultSession.ExecuteCommand(cmd,TimeSpan.FromSeconds(30));} 
			catch (Exception ex) {
				return ex.ToString();//ex.GetType().Name + "\r\n"+ ex.Message);
			}
			return cmd.Result.ToString();
		}
	}
}
